import { createPinia } from 'pinia'
import { createApp } from 'vue'

import '@/assets/const.css'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import zhCn from 'element-plus/es/locale/lang/zh-cn'
import App from './App.vue'
import Login from './Login.vue'
import router from './router'
import { DEV } from "@/config/env";
import { loginApi } from "./api/Api";



/** 测试环境下登录页拦截，如果不拦截则无须进入主页，仅测试环境生效 */
var loginPageFilter = true

console.log(typeof window == 'object');

if (DEV && !loginPageFilter) {
    AppPage()
} else {
    let body = new FormData()
    body.append("login", "check");
    loginApi.login({
        body: body,
        success: (data: any) => {
            if (data.status == "success") {
                AppPage()
            } else {
                loginPage()
            }
        },
        fail: (err: any) => {
            loginPage()
        }
    })
}

/** 登录页 */
function loginPage() {
    const app = createApp(Login);
    app.use(createPinia())
    app.use(ElementPlus, { locale: zhCn, })
    app.mount('#app')
}

/** 应用页 */
function AppPage() {
    const app = createApp(App);
    app.use(router);
    app.use(createPinia())
    app.use(ElementPlus, { locale: zhCn, })
    app.mount('#app')
}